<template>
  <view class="container">
    <!-- 股票基本信息卡片 -->
    <view class="stock-card">
      <view class="stock-header">
        <view>
          <text class="stock-name">{{ stockContent.name }}</text>
          <text class="stock-code">{{ stockContent.stock_num }}</text>
        </view>
        <view class="market-tag">{{ stockContent.market }}</view>
      </view>

      <view class="stock-data-grid">
        <view class="data-item">
          <text class="data-label">当前价格</text>
          <text class="data-value price">{{ stockContent.sprice }}</text>
        </view>
        <view class="data-item">
          <text class="data-label">市盈率</text>
          <text class="data-value">{{ stockContent.pe }}</text>
        </view>
        <view class="data-item">
          <text class="data-label">募集资金</text>
          <text class="data-value">{{ stockContent.realm }}</text>
        </view>
        <view class="data-item">
          <text class="data-label">成立日期</text>
          <text class="data-value">{{ stockContent.rdate }}</text>
        </view>
      </view>
    </view>

    <!-- 公司信息卡片 -->
    <view class="company-card">
      <text class="card-title">公司信息</text>
      <view class="company-info">
        <view class="info-row">
          <text class="info-label">公司名称</text>
          <text class="info-value">{{ stockContent.name }}</text>
        </view>
        <view class="info-row">
          <text class="info-label">英文名称</text>
          <text class="info-value">{{ stockContent.ename }}</text>
        </view>
        <view class="info-row">
          <text class="info-label">公司地址</text>
          <text class="info-value">{{ stockContent.addr }}</text>
        </view>
        <view class="info-row">
          <text class="info-label">经营范围</text>
          <text class="info-value">{{ stockContent.bscope }}</text>
        </view>
        <view class="info-row">
          <text class="info-label">联系电话</text>
          <text class="info-value">{{ stockContent.phone }}</text>
        </view>
        <view class="info-row">
          <text class="info-label">电子邮箱</text>
          <text class="info-value">{{ stockContent.email }}</text>
        </view>
        <view class="info-row">
          <text class="info-label">上市日期</text>
          <text class="info-value">{{ stockContent.ldate }}</text>
        </view>
      </view>
    </view>

    <!-- 底部操作栏 -->
    <view class="action-bar">
      <button class="action-btn favorite-btn">
        <i class="fa fa-star-o"></i> 收藏
      </button>
      <button class="action-btn trade-btn">
        <i class="fa fa-line-chart"></i> 交易
      </button>
    </view>
  </view>
</template>
<script lang="ts" setup>
import { ref, onMounted } from "vue";
import { useRoute } from "vue-router";
import axios from 'axios';
const stockInfo = ref({});
const stockContent = ref({});

const stockId = useRoute().query.id;;
// 初始化股票数据
onMounted(async () => {
  try {
    const res = await axios.get('/stock/get/'+stockId);
    stockInfo.value = res.data.data;
    stockContent.value = JSON.parse(res.data.data.content);
  } catch (error) {
    uni.showToast({
      title: "数据加载失败",
      icon: "none",
    });
  }
});

</script>

<style lang="scss">
.container {
  padding: 20px 15px 80px; // 为底部操作栏留出空间
  background-color: #f5f5f5;
  min-height: 100vh;
}

.stock-card, .company-card {
  background-color: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  padding: 20px;
  margin-bottom: 15px;
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  }
}

.stock-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.stock-name {
  font-size: 24px;
  font-weight: bold;
  color: #333;
}

.stock-code {
  font-size: 14px;
  color: #666;
  margin-left: 8px;
}

.market-tag {
  background-color: #e6f7ed;
  color: #389e0d;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 16px;
  font-weight: 500;
}

.stock-data-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.data-item {
  background-color: #fafafa;
  padding: 12px;
  border-radius: 8px;
}

.data-label {
  font-size: 12px;
  color: #999;
  display: block;
  margin-bottom: 4px;
}

.data-value {
  font-size: 18px;
  font-weight: 500;
  color: #333;
}

.price {
  color: #f5222d;
}

.card-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin-bottom: 16px;
  display: block;
}

.company-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.info-row {
  display: flex;
  align-items: center;
}

.info-label {
  width: 80px;
  font-size: 14px;
  color: #666;
}

.info-value {
  flex: 1;
  font-size: 14px;
  color: #333;
  word-break: break-word;
}

.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #fff;
  padding: 12px 15px;
  display: flex;
  gap: 10px;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
}

.action-btn {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.favorite-btn {
  background-color: #f0f0f0;
  color: #666;
}

.trade-btn {
  background-color: #f5222d;
  color: #fff;
}
</style>
